package nettyclient;

import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;
import ui.AbstractFrame;
import ui.Frame.AdminFrame;

/**
 * @author Hujf
 * @title: RegesterHandler
 * @date 2021/2/15 0015下午 8:04
 * @description: TODO
 */
public class ClientRegesterHandler extends SimpleChannelInboundHandler {
    public static  AbstractFrame frame;
    private String s1 ;
    private String s2 ;
    private int code;
    public ClientRegesterHandler(String s1, String s2,int code,AbstractFrame n) {
        this.s1 = s1;
        this.s2 = s2;
        this.code = code;
        frame= n;
    }

    @Override
    protected void channelRead0(ChannelHandlerContext ctx, Object msg) throws Exception {
        if(code==1){
            System.out.println("用户注册逻辑");
            //ctx.writeAndFlush("用户注册逻辑");
            ctx.close();
        }else if(code ==2){
            System.out.println("用户登录逻辑");
            if(frame!=null){
                frame.setjTextArea2(frame.getjTextArea2()+msg);
            }
            //ctx.writeAndFlush((String)msg);
        }else{

        }


    }

    @Override
    public void channelActive(ChannelHandlerContext ctx) throws Exception {
        ctx.writeAndFlush(code+"&"+s1+"&"+s2);
    }
}
